package org.example.rmsmsapi.sdao;

import org.apache.ibatis.annotations.*;
import org.example.rmsmsapi.dynamicSql.srmSqlProvider;
import org.example.rmsmsapi.model.*;

import org.example.rmsmsapi.model.Req.bankInfo;
import org.example.rmsmsapi.model.Req.dzddetailreq;
import org.example.rmsmsapi.model.Req.liquiReq;
import org.example.rmsmsapi.model.Req.qsdataReq;
import org.example.rmsmsapi.model.Res.insuinfobydateReq;
import org.example.rmsmsapi.model.Res.qsdRes;
import org.example.rmsmsapi.model.Res.qsdetailRes;
import org.example.rmsmsapi.model.Res.userinfoRes;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface smapper {
    @Select("select userId,userCode,roleid,userName,hosId,userType,createTime,loginTime,stop,token,introduction, avatar FROM userinfo where userCode=userCode and passWord=passWord and stop='0'")
    suser GetUserByUserCodeAndPass(@Param("userCode") String userCode,@Param("passWord")String passWord);
    @Select("select hosId,hosName from hosInfo where stop='0'")
    //获取医院键值对，用于前端选择医院
    List<hosmapInfo> GethosMap();
   @Select("select COUNT(id) bs,CONVERT(DECIMAL(10, 2),SUM(ecbxje)) je,tpname,tpcode from " +
           "insusecond nolock where createtime>#{startTime} and createtime<#{endTime} and userCode=#{userCode} and sfzf<>'1'  and sfdz=#{sfdz} group by tpname,tpcode ")
    //按类型获取需要对账的信息
   List<renclitype>GetAllRenclitype(@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("userCode")String userCode,@Param("sfdz")String sfdz);
    //按类型获取需要对账的信息
   @SelectProvider(type = srmSqlProvider.class,method ="GetdzmxByType")
    List<renclitype>GetAllRenclitypeProvider(dzdinfo d);
   @SelectProvider(type = srmSqlProvider.class,method = "GetnotRencinfo")
   //获取未对账信息
   List<norencque> GetnoRenc(norencque q);
  @Select("select userCode,userName,a.hosId,appid,hosName,hoslevel,hosCode from userinfo a with(nolock) " +
          "left join hosInfo b with(nolock)  on a.hosId=b.hosId where userCode=#{userCode}")
  /**获取人员和医院信息**/
  usandhosinfo Getryandhosinfo(@Param("userCode")String userCode);
   @Select( "select SUM(ecbxje) zje from insusecond nolock" +
           " where createtime>=#{startTime} and createtime<=#{endTime} and userCode=#{userCode} and sfzf<>'1' and sfdz<> '1' ")
   String Getdzzje(@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("userCode")String userCode);
   @Select("select top 1 createtime from insusecond where userCode=#{userCode} and sfdz=#{sfdz} and sfzf='0'  order by createtime asc")
   /**获取对账开始时间**/
   String GetDZcreatetime(@Param("userCode")String userCode,@Param("sfdz")String sfdz);
   @Update("update userinfo set loginTime=#{logintime} where userId=#{userId}")
    void uPuser(@Param("userId")String userId,@Param("logintime")String logintime);
    @Select("select  roleId,router from userPermis where userCode=#{userCode}")
    List<mroles> GetRoles(@Param("userCode")String userCode);
    @Select("select  router from userPermis where userCode=#{userCode}")
    ArrayList<String> GetRolesByCode(@Param("userCode")String userCode);
    @Select("select pathName from role a with(nolock) left join Rcp b with(nolock)  on a.roleid=b.roleid left " +
            "join perInfo c with(nolock) on b.perid=c.perid where a.roleid=#{roleid}")
    //通过角色ID获取权限信息
    ArrayList<String>GetPermes(@Param("roleid") String roleid);
    @SelectProvider(type = srmSqlProvider.class,method = "GetsyspesonInfo")
  //获取退役军人信息
    List<rmspeson> GetRMsperinfo(rmspeson r);
@UpdateProvider(type = srmSqlProvider.class,method = "UprmsInfo")
  /**更新tyjr信息**/
   void  upRsms(rmspeson r);
   @UpdateProvider(type = srmSqlProvider.class,method = "uprmsRencli")
  //更新报销单的对账信息
   void upRencliRmesdeta(dzdinfo r);
 @InsertProvider(type = srmSqlProvider.class,method = "InsrtmsInfo")
   //新增退役军人信息
   void  insertRsms(rmspeson r);
    @InsertProvider(type = srmSqlProvider.class,method = "Inrencli")
    //新增对账单
    void  insertRencli(dzdinfo r);
    @InsertProvider(type = srmSqlProvider.class,method = "insudoSQLprovider")
  //增加报账信息
   void insudop(insudoReq req);
    @UpdateProvider(type = srmSqlProvider.class,method ="UphosdzCancle")
// 作废对账单
    void Canclehosdzd(dzdinfo req);
    @UpdateProvider(type = srmSqlProvider.class,method ="uprmshosdzd")
  //作废对账单明细
    void uprmshosdzd(dzdinfo req);
    @SelectProvider(type = srmSqlProvider.class,method = "Getinsudoinfo")
        //获取退役军人信息
    List<insudoReq> GetinsuInfo(insudoReq req);

    @Select("select case #{sfjsff} when '1' then bxbl else bxbl1 end as bl from personType where tpcode=#{tpcode}")
    //获取报销比列
    String getbxbl(@Param("sfjsff")String sfjsff,@Param("tpcode")String tpcode);
    @SelectProvider(type = srmSqlProvider.class,method = "Getdzdinfo")
        //获取对账单信息用于医院对账使用
    List<dzdinfo> Getdzlist(dzdinfo req);

    @SelectProvider(type = srmSqlProvider.class,method = "Getdzdinfobydzsj")
        //获取对账单信息通过时间
    List<dzdinfo> Getdzlistbytime(dzdinfo req);
    @SelectProvider(type = srmSqlProvider.class,method = "getrecinsutpbytm")
    //通过类型和时间、对账单号获取报销明细信息
    List<insudoReq> GetrecldetailBytptime(dzddetailreq r);
    @SelectProvider(type = srmSqlProvider.class,method = "Getqsinfodetail")
/***获取详细清算信息***/
    List<qsdetailRes> GetqsinfoDetail(qsdataReq r);
    @SelectProvider(type = srmSqlProvider.class,method = "getqsjeinfo")
        //获取清算金额和笔数
    qsjeinfo Getqsje(liquiReq r);

    @UpdateProvider(type = srmSqlProvider.class,method = "Upqsdatainfo")
        //保存清算表时候更新明细表中的清算信息
    void Upqsdetail(qsdRes r);
    @UpdateProvider(type = srmSqlProvider.class,method = "Upqsdatainfo1")
        //更新清算表时候更新明细表
    void Upqsdetail1(qsdRes r);
    @SelectProvider(type = srmSqlProvider.class,method = "GetinsoinfoDetail")
    /**获取退役军人报销明细信息**/
    List<insudoReq> GetinsoinfoDetail(insuinfobydateReq req);
    @UpdateProvider(type = srmSqlProvider.class,method = "upinsuinfopro")
//   更新结算表，主要用于作废
    void upjsinfo(insudoReq r);
    @SelectProvider(type = srmSqlProvider.class,method = "Inserqsd")
    /**保存清算表**/
   void saveqsb(qsdRes r);
   @UpdateProvider(type = srmSqlProvider.class,method = "upqsbqsinfo")
   /**更新清算表**/
   void upqsbinfo(qsdRes r);
    @SelectProvider(type = srmSqlProvider.class,method = "Getqsxx")
    /**获取清算表信息**/
    List<qsdRes> Getqsinfo(qsdRes req);
    @SelectProvider(type = srmSqlProvider.class,method = "getHosinfo")
//获取医院信息
    List<hosinfo> Gethosinfos(hosinfo req);
    @SelectProvider(type = srmSqlProvider.class,method = "getRoleInfo")
//获取校色信息
    List<roleModel> Getroleinfos(roleModel req);
    @SelectProvider(type = srmSqlProvider.class,method = "getUserinfo")
//获取用户信息
    List<userinfoRes> GetUserinfos(userinfoModel r);
    @SelectProvider(type = srmSqlProvider.class,method = "GetPersonTypeinfo")
//获取用户类型信息
    List<personTypeModel> GetPersonTypeinfo(personTypeModel r);

    @UpdateProvider(type = srmSqlProvider.class,method = "updateHosinfo")
  //更新医院信息
    void updateHosinfo(hosinfo req);


    @UpdateProvider(type = srmSqlProvider.class,method = "UpdatePersonType")
        //更新人员类型信息
    void UpdatePersonType(personTypeModel r);
    @UpdateProvider(type = srmSqlProvider.class,method = "upUserinfo")
        //更新用户信息
    void upUserinfo(userinfoModel r);

    @UpdateProvider(type = srmSqlProvider.class,method = "upRoleInfo")
        //更新角色信息
    void upRoleInfo(roleModel req);
    @InsertProvider(type = srmSqlProvider.class,method = "addUserinfo")
    void addUserinfo(userinfoModel r);

    @InsertProvider(type = srmSqlProvider.class,method = "SaveBankInfo")
  //新增银行卡信息
    void saveBankInfo(bankInfo b);
    @UpdateProvider(type = srmSqlProvider.class,method = "UpdateBankInfo")
 //更新银行卡信息
    void UpdateBankInfo(bankInfo b);
    @InsertProvider(type = srmSqlProvider.class,method = "saveHosinfo")
    void insertHosinfo(hosinfo req);
    @InsertProvider(type = srmSqlProvider.class,method = "addRoleInfo")
    //新增角色
    void addRoleInfo(roleModel req);

 @InsertProvider(type = srmSqlProvider.class,method = "AddPersonType")
  //新增人员类型信息
 void AddPersonType(personTypeModel r);
    @SelectProvider(type = srmSqlProvider.class,method = "Getqsxxlist")
    /**获取清算表信息查询用于清算更新和作废用**/
    List<qsdRes> Getqsinfo1(qsdRes req);
    @Select("select userId,userCode,roleid,userName,hosId,userType,createTime,loginTime,stop,introduction, avatar,password FROM userinfo where userCode=#{userCode} and stop='0'")
  /***通过用户名获取用户信息*/
    suser GetUserByUserCode(@Param("userCode")String userCode);
    @Select("select  tpcode,tpname from personType where stop ='0'")
  //获取人员类型
    List<rmsType> GetRmsTpInfo();
    @Select("select cbdmc from Yb_cbd where cbdbh=#{cbdbh}")
    //获取参保地类型
    String GetYbCbd(@Param("cbdbh")String cbdbh);
    @Select("select TOP 1 b.tpcode,b.tpname,b.bxbl from personInfo a with(nolock) left join personType b with(nolock) on a.tpcode=b.tpcode and a.stop='0' where a.idcardNo=#{idcardNo}")
    /**获取退役军人类型**/
    RsmTpBean getRmsTpBeanByCard(@Param("idcardNo") String idcardNo);
    @Select("select roleid,rolename from role WHERE stop='0'")
  //获取角色数组
    List<roleMap> GetRoleMap();
    @Select("select hosId,hosName  from hosInfo WHERE stop='0'")
 //获取医院数组
    List<hosMap>GetHosMap();
@Select("select perid,pathName,name from perInfo")
 //获取权限信息
List<perInfo> GetPerinfos();
@Select("select rcpid,roleid,perid,operaCode,operaName,checked from Rcp where roleid =#{roleid}")
//获取角色对应权限
List<RcpModel>  GetrcpList(@Param("roleid")String roleid);
@Delete("delete Rcp  where roleid =#{roleid} ")
//删除某个角色的权限
   void DeleteRcp(@Param("roleid")String roleid);
@InsertProvider(type = srmSqlProvider.class,method = "InserRcp")
//添加角色对应权限信息
    void InsertRcp(RcpModel req);
@Select("select rowId,name, idcardNo,bankCardName,bankCardNo,phone,bzms,editUser,editName,editTime from bankInfo(nolock) where idcardNo=#{idcardNo}")
 /**获取退役军人银行卡信息***/
List<bankInfo>   GetbankInfo(@Param("idcardNo")String idcardNo);
}
